/**
 * @param {number[][]} towers
 * @param {number} radius
 * @return {number[]}
 */
var bestCoordinate = function (towers, radius) {
  let xMax = Number.MIN_VALUE,
    yMax = -Number.MAX_VALUE
  for (const tower of towers) {
    let x = tower[0],
      y = tower[1]
    xMax = Math.max(xMax, x)
    yMax = Math.max(yMax, y)
  }
  let cx = 0,
    cy = 0
  let maxResult = 0
  for (let i = 0; i <= xMax; i++) {
    for (let j = 0; j <= yMax; j++) {
      let res = 0
      for (let k = 0; k < towers.length; k++) {
        let X = Math.pow(towers[k][0] - i, 2)
        let Y = Math.pow(towers[k][1] - j, 2)
        if (Math.sqrt(X + Y) <= radius) {
          res += Math.floor(towers[k][2] / (1 + Math.sqrt(X + Y)))
        }
      }
      if (res > maxResult) {
        cx = i
        cy = j
        maxResult = res
      }
    }
  }
  console.log(cx, cy)
  return [cx, cy]
}

bestCoordinate(
  [
    [1, 2, 13],
    [2, 1, 7],
    [0, 1, 9],
  ],
  2
)
